$TITLE  GTAPinGAMS -- Static Multiregional Core Model in MPSGE Syntax

*	Note:

*		This is the model implemented in MPSGE.

*		This implementation accomodates both constant-elasticity of
*		transformation between production for domestic and export
*		markets (eta < +INF), and perfect substitution between 
*		those markets (eta=+INF).

*		Variables, equations and GAMS keywords are in UPPER case.
*		Sets and parameters are in lower case.

*	Read the dataset using the standard routine:

set	i(*), r(*), d(*), f(*);
$gdxin 'mge.gdx'
$load i r d f

ALIAS (i,j), (r,s), (r,rr);

SET     num(R)  Identifies the numeraire region,
	cgd(i)  Identifies the investment good /cgd/;


PARAMETER
	eta	Elasticity of transformation - domestic vs. exports,
	esubdm	Elasticity of substitution - domestic vs. imports,
	esubmm  Elasticity of substitution - imports,

* Ken adds explicit dimensions to get the GDX and HAR dimensions full
* (Tom) vim(i,r)        Total value of imports (gross tariff)
        vim(i,r)        Total value of imports (gross tariff) [[i*r]]
        vxm(i,r)        Value of export (net excise tax) [[i*r]]
        vdm(i,r)        Value of domestic output (net excise tax) [[i*r]]
        vdfm(i,r)       Aggregate intermediate demand (domestic) [[i*r]]
        vifm(i,r)       Aggregate intermediate demand (imported) [[i*r]]

        vom(i,r)        Aggregate output value (gross of tax) [[i*r]]
        vgm(i,r)        Public expenditures [[i*r]]
        vpm(i,r)        Private expenditures [[i*r]]
        vg(r)           Total value of public expenditure [[r]]
        vp(r)           Total value of private expenditure [[r]]
	vi(r)		Total value of investment [[r]]
        vt              Value of trade markups
        vb(r)           Net capital inflows [[r]]

        evoa(f,r)       Value of factor income

        va(d,i,r)       Armington supply [[d*i*r]]
        vd(d,i,r)       Domestic supply [[d*i*r]]
        vm(d,i,r)       Imported supply [[d*i*r]]

        ty(i,r)         Output tax [[i*r]]
        ti(j,i,r)       Intermediate input tax [[j*i*r]]
        tf(f,i,r)       Factor tax [[f*i*r]]
        tx(i,s,r)       Export tax rate (defined on a net basis) [[i*s*r]]
        tm(i,s,r)       Import tariff rate [[i*s*r]]
        tg(i,r)         Tax rates on government demand [[i*r]]
        tp(i,r)         Tax rate on private demand [[i*r]]

        vafm(j,i,r)     Aggregate intermediate inputs [[j*i*r]]
        vfm(f,i,r)      Value of factor inputs (net of tax)  [[f*i*r]]
        vtwr(i,r,s)     Transport services [[i*r*s]]
        vxmd(i,r,s)     Value of commodity trade (fob - net export tax) [[i*r*s]]
        vst(i,r)        Value of international transport sales [[i*r]]
        evoa(f,r)       Value of factor income [[f*r]]

* (Tom)        pmx0(i,s,r)     Reference price of imports,
* (Tom) had comma at end of next few lines
        pmx0(i,s,r)     Reference price of imports [[i*s*r]]
        pmt0(i,s,r)     Reference price of transport services [[i*s*r]]
        pg0(i,r)        Reference price of government demand [[i*r]]
        pc0(i,r)        Reference price for private demand [[i*r]]
        py0(i,r)        Reference output price domestic or export [[i*r]]
        pai0(j,i,r)     Reference price for intermediate inputs [[j*i*r]]
        pf0(f,i,r)      Reference price for factor inputs [[f*i*r]] ;

$load	num eta esubdm esubmm 
$load	vom vim va vdm vxm evoa vafm vfm vd vm 
$load	vtwr vg vgm vp vpm vt vst vb vi vxmd 
$load	pf0 pmx0 pmt0 pg0 pc0
$load	ty ti tf tx tm tg tp
* pai0 seems to have been forgotten by Tom (but is not on GDX file)
* $load pai0 

* Next is from Tom's mge_gp.gms
PARAMETER	vxb(i,s,r)	Bilateral trade flows [[i*s*r]] ;

vxb(i,s,r) = vxmd(i,s,r)*pmx0(i,s,r) + vtwr(i,s,r)*pmt0(i,s,r);

* Addition by Ken
parameter
        ty2(i,r)         Output tax copy of t2 [[i*r]] 
* Ken added py0 which seems to have been forgotten by Tom
        py0(i,r)        Reference price of domestic Output [[i*r]]
        py20(i,r)        Reference price of domestic Output copy of py0 [[i*r]]
        pmx0ken(i,s,r)     Ken Reference price of imports [[i*s*r]]
	esbd   Copy of esubdm to give header expected by MGE2GP
	esbm   Copy of esubmm to give header expected by MGE2GP ;

ty2(i,r) = ty(i,r) ;
* NO py0(i,r) = 1+ty(i,r) ;
py0(i,r) = 1-ty(i,r) ;
py20(i,r) = py0(i,r) ;
pmx0ken(i,s,r) = 1 + tx(i,s,r) + tm(i,s,r)*(1+tx(i,s,r)) ;
* pai0 seems to have been forgotten by Tom
pai0(j,i,r) = 1 + ti(j,i,r) ;
esbd = esubdm ;
esbm = esubmm ;

* Tom had (in mgedata.gms):
* execute_unload 'mge.gdx', i, r, d, f, num, eta, esubdm, esubmm, 
*	vom, vim, va, vdm, vxm, evoa, vafm, vfm, vd, vm, 
*	vtwr, vg, vgm, vp, vpm, vt, vst, evoa, vb, vi, vxmd, 
*	pf0, pmx0, pmt0, pg0, pc0,
*	ty, ti, tf, tx, tm, tg, tp;

execute_unload 'mgeken.gdx', i, r, d, f, num,
* Add aliases and subset cgd
	j, s, cgd,
	eta, esubdm, esubmm, 
	vom, vim, va, vdm, vxm, evoa, vafm, vfm, vd, vm, 
	vtwr, vg, vgm, vp, vpm, vt, vst, evoa, vb, vi, vxmd,
* Add vxb, ty2, py0, py20, pai0, pf0, esbd, esbm, pmx0ken
	vxb, ty2, py0, py20, pai0, pf0, esbd, esbm, pmx0ken,
	pf0, pmx0, pmt0, pg0, pc0,
	ty, ti, tf, tx, tm, tg, tp;

execute 'gdx2har mgeken' ;

